using System.IO;
using UnityEditor;
using UnityEngine;

namespace EntityKit.Editor
{
    public class EntityKitMenuItems
    {
        // === 实体系统 ===
        [MenuItem("Ly Game/实体系统/事件系统查看器", false, 10)]
        public static void ShowEventManagerWindow()
        {
            EventSystemViewerWindow.ShowWindow();
        }
        
        [MenuItem("Ly Game/实体系统/实体模板管理器", false, 12)]
        public static void ShowPrefabTemplateManager()
        {
            PrefabTemplateManager.ShowWindow();
        }

        // === 配置管理 ===
        [MenuItem("Ly Game/配置管理/SO配置", false, 20)]
        public static void ShowCreateConfigAssetWindow()
        {
            ScriptableObjectCreationWindow.ShowWindow();
        }

        [MenuItem("Ly Game/配置管理/Excel配置", false, 21)]
        public static void ShowExcelTools()
        {
            ExcelEditorWindow.ShowExcelTools();
        }

        // === 本地化工具 ===
        [MenuItem("Ly Game/本地化工具/本地化查询", false, 30)]
        public static void ShowLocalizationEditorWindow()
        {
            LocalizationQueryWindow.ShowWindow();
        }

        [MenuItem("Ly Game/本地化工具/本地化配置", false, 31)]
        public static void ShowLocalizationConfigWindow()
        {
            LocalizationWindow.ShowWindow();
        }

        // === 调试分析 ===
        [MenuItem("Ly Game/调试分析/重复资源检查", false, 40)]
        public static void ShowDuplicateAssetCheckerWindow()
        {
            DuplicateAssetCheckerWindow.ShowWindow();
        }

        [MenuItem("Ly Game/调试分析/查找Missing脚本", false, 41)]
        public static void ShowMissingScriptsListWindow()
        {
            FindMissingScriptsWindow.ShowWindow();
        }

        [MenuItem("Ly Game/调试分析/查找脚本引用", false, 42)]
        public static void ShowScriptFinderWindow()
        {
            ScriptReferenceFinder.ShowWindow();
        }

        [MenuItem("Ly Game/调试分析/资源引用分析", false, 43)]
        public static void ShowAssetReferenceAnalyzerWindow()
        {
            AssetReferenceAnalyzer.ShowWindow();
        }

        // === 开发工具 ===
        [MenuItem("Ly Game/开发工具/路径调试/Debug Asset Path", false, 50)]
        [MenuItem("Assets/Debug Asset Path", priority = 1000)]
        public static void DebugAssetPath()
        {
            AssetLocation.DebugAssetPath();
        }

        [MenuItem("Ly Game/开发工具/路径调试/Debug Addressable Path", false, 51)]
        [MenuItem("Assets/Debug Addressable Path", priority = 1001)]
        public static void DebugAddressablePath()
        {
            AssetLocation.DebugAddressablePath();
        }
        
        [MenuItem("Ly Game/开发工具/路径调试/Debug Entity Component Prefab Sub Path", false, 52)]
        [MenuItem("GameObject/Debug Entity Component Prefab Sub Path", false, 1002)]
        public static void CopyEntityComponentPathToClipboard()
        {
            EntityComponentSubLocation.CopyEntityComponentPathToClipboard();
        }

        [MenuItem("Ly Game/开发工具/路径调试/Debug Bind Behaviour Sub Path", false, 53)]
        [MenuItem("GameObject/Debug Bind Behaviour Sub Path", false, 1003)]
        public static void CopyBindBehaviourPathToClipboard()
        {
            BindBehaviourSubLocation.CopyBindBehaviourPathToClipboard();
        }
        
        // 屏幕截图
        [MenuItem("Ly Game/开发工具/屏幕截图/默认分辨率", false, 60)]
        public static void TakeDefaultScreenshot()
        {
            ScreenshotUtility.TakeDefaultScreenshot();
        }

        [MenuItem("Ly Game/开发工具/屏幕截图/主相机4K", false, 61)]
        public static void TakeMainCameraShot4K()
        {
            ScreenshotUtility.TakeMainCameraShot4K();
        }

        [MenuItem("Ly Game/开发工具/屏幕截图/主相机8K", false, 62)]
        public static void TakeMainCameraShot8K()
        {
            ScreenshotUtility.TakeMainCameraShot8K();
        }

        [MenuItem("Ly Game/开发工具/屏幕截图/主相机超高清", false, 63)]
        public static void TakeMainCameraShotUHD()
        {
            ScreenshotUtility.TakeMainCameraShotUHD();
        }

        // 代码工具
        [MenuItem("Ly Game/开发工具/代码导出", false, 70)]
        public static void ShowCodeExportWindow()
        {
            CodeExportWindow.ShowCodeExportWindow();
        }

        // Unity 应用程序路径
        [MenuItem("Ly Game/开发工具/应用程序路径/StreamingAssets", false, 71)]
        public static void OpenStreamingAssets()
        {
            string streamingAssetsPath = Application.streamingAssetsPath;
            if (!Directory.Exists(streamingAssetsPath))
            {
                Directory.CreateDirectory(streamingAssetsPath);
            }

            EditorUtility.RevealInFinder(streamingAssetsPath);
        }

        [MenuItem("Ly Game/开发工具/应用程序路径/PersistentData", false, 72)]
        public static void OpenPersistentData()
        {
            string persistentDataPath = Application.persistentDataPath;
            if (!Directory.Exists(persistentDataPath))
            {
                Directory.CreateDirectory(persistentDataPath);
            }

            EditorUtility.RevealInFinder(persistentDataPath);
        }

        [MenuItem("Ly Game/开发工具/应用程序路径/TemporaryCache", false, 73)]
        public static void OpenTemporaryCache()
        {
            string temporaryCachePath = Application.temporaryCachePath;
            if (!Directory.Exists(temporaryCachePath))
            {
                Directory.CreateDirectory(temporaryCachePath);
            }

            EditorUtility.RevealInFinder(temporaryCachePath);
        }

        [MenuItem("Ly Game/开发工具/应用程序路径/DataPath", false, 74)]
        public static void OpenDataPath()
        {
            EditorUtility.RevealInFinder(Application.dataPath);
        }

        [MenuItem("Ly Game/开发工具/应用程序路径/ConsoleLog", false, 75)]
        public static void OpenConsoleLog()
        {
#if UNITY_EDITOR_WIN
            string logPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Unity", "Editor", "Editor.log");
#elif UNITY_EDITOR_OSX
            string logPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Library", "Logs", "Unity", "Editor.log");
#elif UNITY_EDITOR_LINUX
            string logPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "unity3d", "Editor.log");
#endif
            if (File.Exists(logPath))
            {
                EditorUtility.RevealInFinder(logPath);
            }
            else
            {
                EditorUtility.DisplayDialog("文件未找到", "Unity编辑器日志文件不存在于预期位置", "确定");
            }
        }

        // === 系统设置 ===
        [MenuItem("Ly Game/系统设置/Game Setting", false, 100)]
        public static void OpenSettings()
        {
            GameSettingProvider.OpenSettings();
        }
    }
}